//
//  ZYViewController.m
//  AutoLayoutDemo
//
//  Created by wanghaijun on 14-1-20.
//  Copyright (c) 2014年 ___WANGHAIJUN___. All rights reserved.
//

#import "ZYViewController.h"

@interface ZYViewController ()

@end

@implementation ZYViewController

- (void)viewDidLoad
{
    
    [super viewDidLoad];

    UILabel* label = [[UILabel alloc]initWithFrame:CGRectMake(50, 50, 60, 20)];
    
    [label setBackgroundColor:[UIColor blueColor]];
    
    label.text = @"this is demo!";
    
    label.translatesAutoresizingMaskIntoConstraints = NO;
    
    [self.view addSubview:label];
    
    NSLayoutConstraint* centerX = [NSLayoutConstraint constraintWithItem:label attribute:(NSLayoutAttributeCenterX) relatedBy:(NSLayoutRelationEqual) toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0f constant:0.0f];
    
    NSLayoutConstraint* centerY = [NSLayoutConstraint constraintWithItem:label attribute:(NSLayoutAttributeCenterY) relatedBy:(NSLayoutRelationEqual) toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1.0f constant:0.0f];
    
//    [self.view addConstraints:@[centerX,centerY]];
    
    //水平方向，左边和父布局保持150距离，右边和父布局保持50距离；
    NSString* constrantString = @"H:|-150-[label]-50-|";
    
    //
    constrantString = @"H:|-(<=50)-[label(>=50)]-(<=100)-|";
    
    NSDictionary* views = NSDictionaryOfVariableBindings(label);
    
    
    NSArray *constrants = [NSLayoutConstraint constraintsWithVisualFormat:constrantString options:0 metrics:nil views:views];
    
    [self.view addConstraints:constrants];
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
